<form class="ui-body ui-body-a ui-corner-all" id="taskFormWateringS">
	<div class="ui-field-contain">
		<label for="textinput-type">Type:</label> <input
			type="text" name="textinput-type" id="textinput-type"
			placeholder="Type" value="<%=type%>" readonly="readonly">
	</div>
	
	<div class="ui-field-contain">
		<label for="textinput-account">Account:</label> <input
			type="text" name="textinput-account" id="textinput-account"
			placeholder="Account" value="<%=account%>"
			required>
	</div>
		
	<div class="ui-field-contain">
		<label for="textinput-id">ID:</label> <input
			type="text" name="textinput-id" id="textinput-id"
			readonly="readonly" placeholder="Group ID" value="<%=id%>"
			required>
	</div>

	<div class="ui-field-contain">
		<label for="textinput-name">Name:</label> <input
			type="text" name="textinput-name" id="textinput-name"
			placeholder="Name" value="<%=name%>" required>
	</div>


	<div class="ui-field-contain">
		<label for="textinput-gwid">Gateway ID:</label> <input type="text"
			name="textinput-gwid" id="textinput-gwid"
			placeholder="Gateway ID" value="<%=gwId%>">
	</div>		

	<div class="ui-field-contain">
		<label for="textinput-description">Description:</label> <input type="text"
			name="textinput-description" id="textinput-description"
			placeholder="Description" value="<%=description%>">
	</div>
		
	<input type='submit' data-role="button" data-theme="b" id="submit"
		value="Upload task"></input>
	<script type="text/javascript">
	$('#taskFormWateringS').validate({ // initialize the plugin
		rules : {
			"textinput-account":{
				required : true,
				minlength : 2,
				maxlength : 20,
				remote : {
					url : "/checkTaskAccount",
					dataType : "json",
					dataFilter : function(result) {
						if (result != "true") {
							return "\"" + result + "\"";
						} else {
							return '"true"';
						}
					}
				}		
			},
			"textinput-gwid":{
				required : true,
				minlength : 2,
				maxlength : 20,
				remote : {
					url : "/checkTaskGatewayId",
					dataType : "json",
					data : {
						"account" : function() {
							return $("#taskFormWateringS #textinput-account").val()
						}
					},
					dataFilter : function(result) {
						if (result != "true") {
							return "\"" + result + "\"";
						} else {
							return '"true"';
						}
					}
				}		
			},
			"textinput-name" : {
				required : true,
				minlength : 2,
				maxlength : 20,
				remote : {
					url : "/checkTaskName",
					dataType : "json",
					data : {
						"account" : function() {
							return $("#taskFormWateringS #textinput-account").val()
						}
					},
					dataFilter : function(result) {
						if (result != "true") {
							return "\"" + result + "\"";
						} else {
							return '"true"';
						}
					}
				}
			},
			"textinput-pump" : {
				required : true,
				minlength : 2,
				maxlength : 40,
				remote : {
					url : "/checkTaskPump",
					data : {
						"account" : function() {
							return $("#taskFormWateringS #textinput-account").val()
						}
					},
					dataFilter : function(result) {
						if (result != "true") {
							return "\"" + result + "\"";
						} else {
							return '"true"';
						}
					}
				}
			},

			"textinput-description" : {
				required : true,
				minlength : 2,
				maxlength : 20,
			}
		},

		invalidHandler : function() {
			//console.log('invalid form');
		},

		submitHandler : function(form) {
			//console.log("submitHandler");
			$(form).ajaxSubmit({
				type : 'post',
				url : "/_saveTask",
				success : function(data) {
					if (data == "ok") {
						window.history.back();
					} else {
						var err = 'save task config err:' + data;
						//console.log(err);
						showMsgPopup(err, "#editTaskDlg");
					}
				},
				error : function(XmlHttpRequest, textStatus, errorThrown) {
					//console.log('ajaxSubmit failed:' + errorThrown);
				}
			});
		}
	});
	</script>
</form>